package com.erp.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.erp.common.annotation.Log;
import com.erp.common.core.controller.BaseController;
import com.erp.common.core.domain.AjaxResult;
import com.erp.common.enums.BusinessType;
import com.erp.purchase.domain.PurPurchaser;
import com.erp.purchase.service.IPurPurchaserService;
import com.erp.common.utils.poi.ExcelUtil;
import com.erp.common.core.page.TableDataInfo;

/**
 * 采购员信息：关联采购订单指派Controller
 *
 * @author hfw
 * @date 2025-09-02
 */
@RestController
@RequestMapping("/purchase/purchaser")
public class PurPurchaserController extends BaseController
{
    @Autowired
    private IPurPurchaserService purPurchaserService;

    /**
     * 查询采购员信息：关联采购订单指派列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaser:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurPurchaser purPurchaser)
    {
        startPage();
        List<PurPurchaser> list = purPurchaserService.selectPurPurchaserList(purPurchaser);
        return getDataTable(list);
    }

    /**
     * 导出采购员信息：关联采购订单指派列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaser:export')")
    @Log(title = "采购员信息：关联采购订单指派", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurPurchaser purPurchaser)
    {
        List<PurPurchaser> list = purPurchaserService.selectPurPurchaserList(purPurchaser);
        ExcelUtil<PurPurchaser> util = new ExcelUtil<PurPurchaser>(PurPurchaser.class);
        util.exportExcel(response, list, "采购员信息：关联采购订单指派数据");
    }

    /**
     * 获取采购员信息：关联采购订单指派详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purPurchaserService.selectPurPurchaserById(id));
    }

    /**
     * 新增采购员信息：关联采购订单指派
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaser:add')")
    @Log(title = "采购员信息：关联采购订单指派", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurPurchaser purPurchaser)
    {
        return toAjax(purPurchaserService.insertPurPurchaser(purPurchaser));
    }

    /**
     * 修改采购员信息：关联采购订单指派
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaser:edit')")
    @Log(title = "采购员信息：关联采购订单指派", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurPurchaser purPurchaser)
    {
        return toAjax(purPurchaserService.updatePurPurchaser(purPurchaser));
    }

    /**
     * 删除采购员信息：关联采购订单指派
     */
    @PreAuthorize("@ss.hasPermi('purchase:purchaser:remove')")
    @Log(title = "采购员信息：关联采购订单指派", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purPurchaserService.deletePurPurchaserByIds(ids));
    }
}
